package com.example.mall.web.controller;

import com.example.mall.domain.SalesStatistics;
import com.example.mall.dto.SalesStatisticsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.SalesStatisticsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ISalesStatisticsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salesStatistics")
public class SalesStatisticsController {

    @Autowired
    public ISalesStatisticsService salesStatisticsService;

    /**
     * 分页查询销售数据统计表信息
     * @param salesStatisticsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询销售数据统计表信息",notes = "分页查询销售数据统计表信息",httpMethod = "GET")
    public JSONResult queryPage(SalesStatisticsQuery salesStatisticsQuery){
        PageDTO<SalesStatisticsDto> salesStatisticsDtoPageDTO = salesStatisticsService.queryPage(salesStatisticsQuery);
        return JSONResult.success("查询成功",salesStatisticsDtoPageDTO);
    }

    /**
     * 根据id查询销售数据统计表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询销售数据统计表信息",notes = "根据id查询销售数据统计表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.STAT_STATISTICS_NOT_ID);
        }
        SalesStatistics salesStatistics = salesStatisticsService.getById(id);
        return JSONResult.success("查询成功",salesStatistics);
    }

    /**
     * 根据id查询销售数据统计表信息
     * @param id
     * @return
     */
    @GetMapping("querySalesStatisticsById/{id}")
    @ApiOperation(value = "根据id查询销售数据统计表信息",notes = "根据id查询销售数据统计表信息",httpMethod = "GET")
    public JSONResult querySalesStatisticsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.STAT_STATISTICS_NOT_ID);
        }
        SalesStatistics salesStatistics = salesStatisticsService.querySalesStatisticsById(id);
        return JSONResult.success("查询成功",salesStatistics);
    }

    /**
     * 查询全部销售数据统计表信息
     * @param
     * @return
     */
    @GetMapping("querySalesStatisticsList")
    @ApiOperation(value = "查询全部销售数据统计表信息",notes = "查询全部销售数据统计表信息",httpMethod = "GET")
    public JSONResult querySalesStatisticsList(){
        List<SalesStatistics> salesStatistics = salesStatisticsService.querySalesStatisticsList();
        return JSONResult.success("查询成功",salesStatistics);
    }

    /**
     * 新增销售数据统计表
     * @param salesStatisticsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增销售数据统计表",notes = "新增销售数据统计表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SalesStatisticsDto salesStatisticsDto){
        salesStatisticsService.insert(salesStatisticsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改销售数据统计表信息
     * @param salesStatisticsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改销售数据统计表信息",notes = "修改销售数据统计表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SalesStatisticsDto salesStatisticsDto){
        salesStatisticsService.update(salesStatisticsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除销售数据统计表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除销售数据统计表信息",notes = "删除销售数据统计表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        salesStatisticsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除销售数据统计表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除销售数据统计表信息",notes = "批量删除销售数据统计表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        salesStatisticsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
